package ing.lightDogs.turetJson;

import java.io.IOException;
import java.net.URL;

import javax.servlet.http.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

@SuppressWarnings("serial")
public class TuretJsonServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		try {
			/** Handling XML */
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
			XMLReader xr = sp.getXMLReader();
			/** Create handler to handle XML Tags ( extends DefaultHandler ) */
			Parseturet handler = new Parseturet();
			xr.setContentHandler(handler);
//			URL sourceUrl = new URL("file:c:/turet.xml");
			URL sourceUrl = new URL("http://dl.dropbox.com/u/16617207/Torino%20-%20Turet.xml");
			xr.parse(new InputSource(sourceUrl.openStream()));
//		    sp.parse("http://dl.dropbox.com/u/16617207/Torino%20-%20Turet.xml", handler);
			resp.getWriter().println("parsed: " + handler.ok + " not parsed: " + handler.ko + " errors: " + handler.error);
		} catch (Exception e) {
			resp.getWriter().println("XML Parsing Exception = " + e);
		}
	}
}
